<?php
include("utils.php");
include("watermark_funpast.php");
if($_SESSION['siteuserId']=="")
{
	header("location:index.php");
}
if($_SESSION['langname']=="")
{
	$language_url="languages/"."english".'/sell_website_add_language.php';
}
else
{
	$language_url="languages/".$_SESSION['langname'].'/sell_website_add_language.php';
}
include("$language_url");


if($_REQUEST['mode']=="add_price_save")
{
add_price_save();
}
elseif($_REQUEST['mode']=="delete_price")
{
delete_price();
}
elseif($_REQUEST['mode']=="add_space_save")
{
add_space_save();
}
else
{
main_content("main();");
}

function delete_price()
{
$delete_sql="delete from ".PRICE." where price_id='".$_POST['price_id']."' ";
mysql_query($delete_sql);
$GLOBALS['msg']="Price list deleted successfully.";
main_content("main();");
}

function add_price_save()
{
	
	 $query_price_insert="insert into ".PRICE." 
							set ammount='".$_POST['ammount']."',
								adspaceId='".$_SESSION['adspaceId']."',
								duration='".$_POST['duration']."' ";
	mysql_query($query_price_insert);
	main_content("main();");
}

function add_space_save()
{

if($_SESSION['languageId']!="")
{
	$languageId=$_SESSION['languageId'];
}
else
{
	$languageId='1';
}
	
	/* $selOnclickCalculation=mysql_query("select * from ".PRICE." where adspaceId='".$_SESSION['adspaceId']."'");
	while($fetchVal=mysql_fetch_array($selOnclickCalculation))
	{
		$arr['ammo'][] = $fetchVal['ammount'];
		$arr['dur'][] = $fetchVal['duration'];
	}
	foreach ($arr as $key => $value)
	{
	$total='';
	for($i=0;$i<count($arr[$key]);$i++)
	{
		$total=(float)($total+$arr[$key][$i]);
	}
	$arrayTotal[]=$total;
	}
	$clickAount=($arrayTotal[0]/$arrayTotal[1]); */

// costPerClick='".$clickAount."'
	 $query_space_insert="update ".ADSPSCEMASTER." 
							set adSpaceName='".$_POST['name']."',
								readyDate='".$_POST['lastDate']."',
								langId='".$languageId."',
								description='".$_POST['description']."',
								tags='".$_POST['tags']."' where adspaceId='".$_SESSION['adspaceId']."'";
	mysql_query($query_space_insert);

################ For file upload coding on 01_07_09 starts ##################

if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  $file_name = $_FILES["file"]["name"];
  $extension = explode('.',$file_name);
  $adSpace_image = $_SESSION[adspaceId] .".".$extension[1];
  $folder_original="upload_adspace_image";
  $folder_thumbnail="upload_adspace_image_thumb";
  $thumb_height='147px';
  $thumb_width='201px';
  move_uploaded_file($_FILES["file"]["tmp_name"],"upload_adspace_image/" . $_SESSION[adspaceId] .".".$extension[1]);

watermark_funpast($adSpace_image,$folder_original,$folder_thumbnail,$thumb_height,$thumb_width);
//watermark_funpast($imagename,$folder,$folder_thumb,$height_argu,$width_argu)
  }

#################### End of file upload query on 01_07_09 ends #################

$query_space_image_update="update ".ADSPSCEMASTER." 
							set adSpace_image='".$adSpace_image."' where adspaceId='".$_SESSION['adspaceId']."'";
mysql_query($query_space_image_update);

	//header("location:get_code.php");
	echo '<script>window.location="get_code.php?tab=sell_ads&subMenu=2";</script>';
	main_content("main();");
}

function main()
{
?>
<script language="javascript" type="text/javascript" src="JavaScripts/datetimepicker.js"></script>
<script language="JavaScript">

function changeValue(strValue, strLength, countId, e) {
 if(e.which=='13')
{
 var message_desc = "Please Enter The Description Without Pressing Enter Key";
 alert(message_desc);
 return false
}
        if (strValue.length <= strLength) {
            if (strValue != null) {
                document.getElementById(countId).innerHTML = (strLength - strValue.length);
                if (countId == 'tagsCount' && (strValue.indexOf('"') >= 0 || strValue.indexOf("'") >= 0 || strValue.indexOf("|") >= 0 || strValue.indexOf("\\") >= 0)) {
                    var message = "Invalid tag, please re-enter tags without |, \', \", \\ in it.";
                    alert(message);
            }
            }
        }
        else {
            document.getElementById(countId).innerHTML = "<span style=\"color:red\">Too many characters for description!</span>";
        }
    }


function delete_price(price_id)
		{
			var FAQResp = window.confirm("Are you sure to remove the selected User?");
			if( FAQResp == true )
			{
				
				document.getElementById('mode').value='delete_price';
				document.getElementById('price_id').value=price_id;
				//add_price
				document.getElementById('add_price').submit();
			}
		}


function IsNumeric(sText)

{
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function check_price()
{
	if(document.getElementById('ammount').value=="")
	{
		
		document.getElementById('ammount').focus();
		document.getElementById("msg").innerHTML="Please insert ammount";
		return false;
	}
	if(document.getElementById('duration').value=="")
	{
		
		document.getElementById('duration').focus();
		document.getElementById("msg").innerHTML="Please insert duration";
		return false;
	}
	return true;
}

function check_space()
{
	if(document.getElementById('name').value=="")
	{
		document.getElementById('name').focus();
		document.getElementById("msg_space").innerHTML="Please insert Ad Space Name";
		return false;
	}
	if(document.getElementById('lastDate').value=="")
	{
		document.getElementById('lastDate').focus();
		document.getElementById("msg_space").innerHTML="Please insert Start Date";
		return false;
	}
	if(document.getElementById('lastDate').value!="")
	{
		 if (!IsNumeric(document.getElementById('lastDate').value)) 
   			{ 
				document.getElementById('lastDate').focus();
				document.getElementById("msg_space").innerHTML="Please enter proper Date";
				return false;
			}
	}
	if(document.getElementById('description').value=="")
	{
		document.getElementById('description').focus();
		document.getElementById("msg_space").innerHTML="Please insert Ad Space Description";
		return false;
	}
	return true;
}
</script>
<table width="90%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td valign="top"><?php //include("left_pannel.php"); ?></td>
                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
           <tr>
           <td>
				<body id="tab2">
				<ul id="tabnav">
				<li class="tab1"><a href="#">Build Layout</a></li>
				<li class="tab2"><a href="sell_space_add_details.php">Add Details</a></li>
				<li class="tab3"><a href="#">Get Code</a></li>
				</ul>
				</body>
		  </td>
          </tr>

		<tr>
           <td class="font-11 latest_heading2" align="left" style="padding-left:20px;">
						<strong>Describe your Ad Space for the Ad Marketplace.Include tags for advanced targeting.</strong>
					</td>
          </tr>

<?php
if($GLOBALS['msg']!="")
{
?>
		<tr><TD align="center" style="padding-top:10px;" class="font-11 latest_heading2"><?php echo $GLOBALS['msg'];?></TD></tr>
<?php
}
?>
		<tr><TD>&nbsp;</TD></tr>

		   <tr>
           <td align="center">

				<!--<table style="width: 60%; text-align: center;" border="1" cellspacing="0" cellpadding="0">
				<tr><td style="background-color: rgb(153, 153, 153);" align="left"><font style="text-align: left; color: rgb(255, 255, 255); font-weight: bold;">Product Price List</font></td></tr>
          		 <tr>
           			<td align="center">
				<form name="add_price" method="POST" action="" id="add_price">
				
				<input type="hidden" name="mode" id="mode" value="add_price_save">
				<input type="hidden" name="price_id" id="price_id" value="">
				
				<table width="60%" border="0" cellspacing="0" cellpadding="0">
          		
				<tr>
           			<td class="font-11 latest_heading2">
					<strong>Price($)</strong>
					</td>
					<td class="font-11 latest_heading2">
					<strong>Duration(Days)</strong>
					</td>
					<td>
					&nbsp;
					</td>
				</tr>
				<?php
				$sql_price_fetch="select * from ".PRICE." where adspaceId='".$_SESSION['adspaceId']."' ";
				$query_price_fetch=mysql_query($sql_price_fetch);
				$num=mysql_num_rows($query_price_fetch);
				if($num>0)
				{
				while($row_price_fetch=mysql_fetch_array($query_price_fetch))
				{
				?>
				<tr>
           			<td class="font-11 latest_heading2">
					$<?php echo $row_price_fetch['ammount'];?>
					</td>
					<td class="font-11 latest_heading2">
					<?php echo $row_price_fetch['duration'];?>
					</td>
					<td class="font-11 latest_heading2">
					<span onclick="return delete_price(<?php echo $row_price_fetch['price_id'];?>);">Delete</span>
					</td>
				</tr>
				<?php
					}
					}
					else
					{
				?>
				<tr>
           			<td class="font-11 latest_heading2" colspan="3" align="center">
					No records found.
					</td>
					
				</tr>
				<?php
				}
				?>
				<tr><TD colspan="3" style="padding-top:20px;padding-bottom:20px;"><hr></TD></tr>
				<tr><TD colspan="3" id="msg" class="font-12 black advertise_tableTxt" align="center"></TD></tr>
				<tr>
           			<td class="font-11 latest_heading2">
					<input name="ammount" type="text" style="width: 150px;" maxlength="150" id="ammount" class="InputBox">
					</td>
					<td class="font-11 latest_heading2">
					<input name="duration" type="text" style="width: 150px;" maxlength="150" id="duration" size="15" class="InputBox">
					</td>
					<td class="font-11 latest_heading2">
					<input name="button3" type="submit" class="SubmitInputButton" id="button3" value="Submit" onclick="return check_price();">
					</td>
				</tr>
				<tr><TD colspan="3" style="padding-top:20px;padding-bottom:20px;">&nbsp;</TD></tr>
				</table>
				</form>
				
			</td>
			</tr>
			</table>-->
		  </td>
          </tr>
		<tr><TD>&nbsp;</TD></tr>
		<tr><TD align="center">
		<!-- start table  -->
			<table id="tablePrice" style="width: 60%; text-align: center;" align="center">
      <tbody><tr>
     <td style="padding-top: 25px;" colspan="3">
     <table style="background-color: rgb(153, 153, 153); width: 100%;" cellpadding="3" cellspacing="1">
  <tbody><tr>
    <td style="text-align: left; color: rgb(255, 255, 255); font-weight: bold;" class="blue-background-small">Describe Ad Space</td>
  </tr>
  <tr style="background-color: rgb(251, 251, 251);">
    <td>

      <div style="padding: 3px; text-align: left;">

       <!-- start table	 -->
		<form name="add_price" method="POST" action="" enctype="multipart/form-data">
		<input type="hidden" name="mode" value="add_space_save">
       <table style="width: 100%; text-align: left;">
         <tbody>

	<tr>
           <td style="width: 40%;" class="font-12 black advertise_tableTxt" colspan="2" align="center" id="msg_space"></td>
         </tr>

	<tr>
           <td style="width: 40%;" class="font-12 black advertise_tableTxt"><span class="redstar">*</span>Ad Space Name:</td>
           <td class="font-12 black advertise_tableTxt"><input id="name" name="name" style="width: 150px;" maxlength="24" class="InputBox" value="" onChange="isChanged=true;" type="text"></td>
         </tr>
         <tr>

           <td style="width: 40%;" class="font-12 black advertise_tableTxt"><span class="redstar">*</span>Date to begin selling your ads:</td>
           <td class="font-12 black advertise_tableTxt">
             <input name="lastDate" type="text" class="InputBox" id="lastDate" style="width: 80px;" maxlength="24" value="" onClick="javascript:NewCal('lastDate','yyyymmdd',false,24);"><a class="dateformat">Date format yyyy-mm-dd</a>
             
           </td>
         </tr>
         <tr>
           <td colspan="2" class="font-12 black advertise_tableTxt"><span class="redstar">*</span>Ad Space Description:(Characters left:&nbsp;<span id="descriptionCount">255</span>)</td>
         </tr>
         <tr>
           <td colspan="2" class="font-12 black advertise_tableTxt"><textarea id="description" name="description" class="InputtextArea" cols="42" rows="5" onChange="isChanged=true;" onKeyUp="javascript:changeValue(this.value, 255, 'descriptionCount',event);"></textarea></td>

         </tr>
         <tr>
           <td colspan="" class="font-12 black advertise_tableTxt">Tags:&nbsp;[Characters left: <span id="tagsCount">100</span>]</td>
           <td colspan=""><input name="tags" id="tags" class="InputBox" style="width: 180px;" maxlength="100" value="" onChange="isChanged=true;" onKeyUp="javascript:changeValue(this.value, 100, 'tagsCount',event)" type="text"></td>
         </tr>

<!--############# code on 01_07_09 starts ############-->
	
	<tr>
           <td style="width: 40%;" class="font-12 black advertise_tableTxt" colspan="2" align="center" id="msg_image_space"></td>
         </tr>

	<tr>
           <td style="width: 40%;" class="font-12 black advertise_tableTxt"><span class="redstar">*</span>Ad Space Image:</td>
           <td class="font-12 black advertise_tableTxt"><input type="file" name="file" id="file" style="width: 150px;" class="InputBox" value="" /></td>
         </tr>
	
<!--############# code on 01_07_09 ends ############-->		
<tr>
           <td colspan="2"><input name="button3" type="submit" class="SubmitInputButton" id="button3" value="Submit" onClick="return check_space();"></td>
         </tr>

       </tbody></table>
		</form>
		<!-- end table -->

           </div>
    </td>
  </tr>
</tbody></table>

		</TD></tr></tbody>
		
		</table>

	<!-- end table  -->

    </td>
  </tr>

</table></td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td>&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
<?php
}

?>